package cn.com.surker.base.ticket.service.impl;

import cn.com.surker.base.ticket.entity.TicketPrintRecord;
import cn.com.surker.base.ticket.dao.TicketPrintRecordDao;
import cn.com.surker.base.ticket.service.TicketPrintRecordService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import cn.com.surker.spring.RestResultDto;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import javax.annotation.Resource;
import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

/**
* <p>
    * 发货单、过磅单打印记录 服务实现类
    * </p>
*
* @author admin
* @since 2025-03-04
*/
@Service
public class TicketPrintRecordServiceImpl extends ServiceImpl<TicketPrintRecordDao, TicketPrintRecord> implements TicketPrintRecordService {

        @Resource
        private TicketPrintRecordDao mapper;


        /**
        * 根据条件查询所有的数据
        * @param dto
        * @return
        */
        public RestResultDto findAll(TicketPrintRecord dto){

            QueryWrapper<TicketPrintRecord> query = new QueryWrapper();
            query.setEntity(dto);
            List<TicketPrintRecord> list = mapper.selectList(query);

            return RestResultDto.success(list);
        }


        /**
        * 分页查询数据
        * @param dto page
        * @return
        */
        public RestResultDto findAllByPage(TicketPrintRecord dto, Page<TicketPrintRecord> page){
            QueryWrapper<TicketPrintRecord> query = new QueryWrapper();
            query.setEntity(dto);
            IPage<TicketPrintRecord> iPage = mapper.selectPage(page,query);

            return RestResultDto.success(iPage);
        }


        /**
        * 新增数据
        * @param dto page
        * @return
        */
        public RestResultDto saveInit(TicketPrintRecord dto){
            int saveStatus = mapper.insert(dto);
            if(saveStatus > 0){
                return RestResultDto.success("保存成功!");
            }else{
                return RestResultDto.success("保存失败!");
            }

        }

        /**
        * 更新数据
        * @param dto page
        * @return
        */
        public RestResultDto update(TicketPrintRecord dto){

            int saveStatus = mapper.updateById(dto);
            if(saveStatus > 0){
                return RestResultDto.success("保存成功!");
            }else{
                return RestResultDto.success("保存失败!");
            }

        }
}